package com.example.administrator.yuejian_2.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.activity.AcDetailActivity;
import com.example.administrator.yuejian_2.bean.ActivitylistBean;
import com.example.administrator.yuejian_2.viewholder.AcListVH;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/9/29.
 */

public class AcListAdapter extends Adapter {

    private List<ActivitylistBean> acList = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;

    public AcListAdapter(Context context,List<ActivitylistBean> acList){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.acList.addAll(acList);

    }




    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_ac,parent,false);
        AcListVH holder = new AcListVH(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        AcListVH activityholder = (AcListVH) holder;
        ActivitylistBean activityList = acList.get(position);

        final String activityName = activityList.getA_name();
        activityholder.acnametextView.setText(activityName);

        int activityLike = activityList.getLiked();
        String likesum = String.valueOf(activityLike);
        activityholder.aclikeTextView.setText(likesum);

        String activityPic = activityList.getA_pic();
        if (!activityPic.equals(""))
            Picasso.with(context).
                    load("http://10.0.2.2/YueJian16/Public/activityphoto/"+activityPic)
                    .into(activityholder.acpicImageView);

        final int aid = activityList.getAid();
        final int cost = activityList.getA_money();
        activityholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, AcDetailActivity.class);
                intent.putExtra("aid",aid);
                intent.putExtra("cost",cost);
                intent.putExtra("activityName",activityName);
                context.startActivity(intent);

            }
        });


    }

    @Override
    public int getItemCount() {
        return acList.size();
    }
}
